#include "shopinfosql.h"

ShopActSql::ShopActSql(string db_name)
{
    m_db_act = QSqlDatabase::addDatabase("QSQLITE");
    m_db_act.setDatabaseName(db_name.c_str() );
    //打开数据库
    if( !m_db_act.open() ) //数据库打开失败
    {
        std::cout<<"open error"<<endl;
    }
}

bool ShopActSql::doSql(string sql_lag)
{
    QSqlQuery query;
    bool ret= query.exec(sql_lag.c_str());
    return ret;

}

ShopActSql::~ShopActSql()
{
    m_dbname.clear();
    m_db_act.close();
}

bool ShopActSql::selectDB(string sql_lag)
{
    bool ret_tag=false;
    //逐行取出
    QSqlQuery query1;
    if(!query1.exec(sql_lag.c_str()))
    {
        cout<<"sql error"<<endl;
        return false;
    }

    while(query1.next()) //一行一行遍历
    {
        //取出当前行的内容
        qDebug()<< query1.value(0).toString()<<"   "<< query1.value(1).toString();

        ret_tag=true;
    }
    return ret_tag;
}






